package the_Crash;

import repast.simphony.space.grid.GridPoint;

public enum Direction {
	North, East, South, West;

	public Direction left()
	{
		if(this.equals(North))
			return West;
		if(this.equals(South))
			return East;
		if(this.equals(West))
			return South;
		if(this.equals(East))
			return North;
		else
			return null;
	}
	public Direction right()
	{
		if(this.equals(North))
			return East;
		if(this.equals(South))
			return West;
		if(this.equals(West))
			return North;
		if(this.equals(East))
			return South;
		else
			return null;
	}
	public boolean isInFront(GridPoint current, GridPoint next)
	{
		if(this.equals(North) && next.getY()>current.getY())
			return true;
		else if(this.equals(South) && next.getY()<current.getY())
			return true;
		else if(this.equals(East) && next.getX()>current.getX())
			return true;
		else if(this.equals(West) && next.getX()<current.getX())
			return true;
		else
			return false;
	}
	
	//***********************************************************
	
	public TravelDirection getTurn(Direction nextDirection){
		if(this.right().equals(nextDirection)){
			return TravelDirection.Right;
		} else if (this.left().equals(nextDirection)){
			return TravelDirection.Left;
		} else {
			return TravelDirection.Straight;
		}
	}
	public Direction getOppsiteHeading() {
		if(this.equals(North))
			return South;
		if(this.equals(South))
			return North;
		if(this.equals(West))
			return East;
		if(this.equals(East))
			return West;
		else
			return null;
	}
	
}

